﻿@model SMECustomerWebsite.Models.ViewModels.CrossSelling.CrossSellingViewModel

@Html.Action("SubMenuSalePerformance", "System")
@Html.Action("CustInfo", "System")
<div class="">
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel">
                <div class="x_title">
                    <div class="col-lg-8 col-md-9 col-sm-8">
                        <div>
                            <h2>@SMECustomerWebsite.Core.Resources.Resource.XSellingRateLimitTitle </h2>
                        </div>
                        <div style="display:inline-block;">
                            <p>@SMECustomerWebsite.Core.Resources.Resource.XSellingRateLimitDesc</p>
                        </div>
                    </div>
                    <ul class="nav navbar-right panel_toolbox">
                        @Html.Action("BusinessDateInfo", "System", new { name = "TBL_XSELLING_RATE_USING_LIMIT" })
                        <li>
                            <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">
                    @switch (Model.CurrentUser.GroupIdentifier)
                    {
                    case "1":
                    <table id="xselling" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingDateApproveHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingSumLimitWCHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingAvailLimitRateHeader (VND)</th>
                                <th class="column-title" width="12%">@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader (%)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    break;
                    case "2":
                    <table id="xselling" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingDateApproveHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingSumLimitWCHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingAvailLimitRateHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader (%)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    break;
                    case "3":
                    <table id="xselling" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingDateApproveHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingSumLimitWCHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingAvailLimitRateHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader (%)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    break;
                    case "4":
                    <table id="xselling" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.IndustryHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingDateApproveHeader.ToUpper()</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingSumLimitWCHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingAvailLimitRateHeader (VND)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader (%)</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.InfoHeader</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    break;
                    default:
                    break;
                    }
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts
{
<script src="~/Scripts/custom_search_table.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="~/scripts/datepicker/moment/moment.min.js"></script>
<script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
<script src="/scripts/tableeditable/dataTables.rowsGroup.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var totalColumn = [
                    { "sName": "CIF", "bSortable": false },
                    { "sName": "NAME", "bSortable": false },
                    { "sName": "VPB INDUSTRY", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "INFO", "bSortable": false }]
        var totalLenCol = 7;
        var totalCifCol = 0;
        var dataSearchTotalMatdt = [{ id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: '@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader' }];
        switch (@Model.CurrentUser.GroupIdentifier)
        {
            case 1:
                totalColumn = [
                       { "sName": "REGION", "bSortable": false },
                       { "sName": "BRANCH", "bSortable": false },
                       { "sName": "DAO", "bSortable": false },
                       { "sName": "MSBO", "bSortable": false },
                       { "sName": "CIF", "bSortable": false },
                       { "sName": "NAME", "bSortable": false },
                       { "sName": "VPB INDUSTRY", "bSortable": false },
                       { "sName": "DATE OPEN", "bSortable": false },
                       { "sName": "DATE OPEN", "bSortable": false },
                       { "sName": "DATE OPEN", "bSortable": false },
                       { "sName": "DATE OPEN", "bSortable": false },
                       { "sName": "INFO", "bSortable": false }];
                totalLenCol = 11;
                totalCifCol = 4;
                dataSearchTotalMatdt = [{ id: 6, text: 'Region' }, { id: 4, text: 'Branch' }, { id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: '@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader' }];
                break;
            case 2:
                totalColumn=  [
                    { "sName": "BRANCH", "bSortable": false },
                    { "sName": "DAO", "bSortable": false },
                    { "sName": "MSBO", "bSortable": false },
                    { "sName": "CIF", "bSortable": false },
                    { "sName": "NAME", "bSortable": false },
                    { "sName": "VPB INDUSTRY", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "INFO", "bSortable": false }];
                totalLenCol = 10;
                totalCifCol = 3;
                dataSearchTotalMatdt = [{ id: 4, text: 'Branch' }, { id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: '@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader' }];
                break;
            case 3:
                totalColumn= [
                    { "sName": "DAO", "bSortable": false },
                    { "sName": "MSBO", "bSortable": false },
                    { "sName": "CIF", "bSortable": false },
                    { "sName": "NAME", "bSortable": false },
                    { "sName": "VPB INDUSTRY", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "DATE OPEN", "bSortable": false },
                    { "sName": "INFO", "bSortable": false }];
                totalLenCol = 9;
                totalCifCol = 2;
                dataSearchTotalMatdt = [{ id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' },{ id: 3, text: '@SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader' }];
                break;
            default:
                break;
        }

        var table = $('#xselling').DataTable({
            "responsive": true,
            "bAutoWidth": true,
            "order": [[0, 'asc']],
            "bServerSide": true,
            rowsGroup: [0, 1, 2,3,4,5,6],
            //"bProcessing": true,
            "sAjaxSource": '@Url.Action("RateLimitData", "Xselling")',
            "fnServerData": function (sSource, aoData, fnCallback) {
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": fnCallback
                });
            },
            "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
            "aoColumns":totalColumn,
            "aoColumnDefs": [{
                "sClass": "column-title",
                "aTargets": [totalLenCol],
                "mRender": function (data, type, full) {
                    return '<a class=\"btn btn-primary btn-xs\" onclick=\"showCustomerInfo(\'' + full[totalCifCol] + '\');\"><i class="fa fa-info"></i></a>';
                }
            }],
            initComplete: function () {
                this.api().columns().every(function () {
                    var column = this;
                    switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                            createFilterRegion(column, '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone)');
                            break;
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                            createFilterBranch(column);
                            break;
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader.ToUpper())':
                            createFilterDate(column);
                            break;
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.XSellingSumLimitWCHeader) (VND)':
                            createFilterBalanceMulti(column,1);
                            break;
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.XSellingAvailLimitRateHeader) (VND)':
                            createFilterBalanceMulti(column,2);
                            break;
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.XSellingRateHeader) (%)':
                            createFilterRange(column, 0, 100);
                            break;
                        case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader.ToUpper())':
                            createFilterMSBOName(column, 1);
                            break;
                        case 'DAO':
                            createFilterMSBOName(column, 2);
                            break;
                        default:
                            if (column.index() < totalLenCol) {
                                var select = $('<input type="text" class="filtet-table">')
                                                        .appendTo($(column.header()))
                                                        .on('keyup change', function () {
                                                            column.search(this.value).draw();
                                                        });
                            }
                            break;

                    }
                });
            },
            "drawCallback": function (settings) {
                $('table.custom_table th').removeClass().addClass('column-title');
            }
        });
    });
</script>
}